import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class MultiLineCellRenderer extends DefaultTableCellRenderer
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column)
	{
		Component component = super.getTableCellRendererComponent(table, value,
				isSelected, hasFocus, row, column);
		String s1 = "";
		String s2 = "";
		String s3 = "";
		String purcent = "";
		String ends = "";
		int start = 0;
		int end = 0;
		float number = 0;
		float pourcentvalue = 0;
		String labelcontent = "";
		Color red = new Color(0, 255, 0);
		Color white = new Color(255, 255, 255);
		Object o = table.getValueAt(row, column);
		if (o != null)
		{
			JLabel label = (JLabel) component;
			labelcontent = label.getText();
			if (label.getText().contains(";"))
			{

				// Trinucleotide
				start = 0;
				end = labelcontent.indexOf(";");
				s1 = labelcontent.substring(start, end);
				// Number of current trinucleotide
				start = end + 1;
				end = labelcontent.indexOf(";", start);
				s2 = labelcontent.substring(start, end);
				number = Integer.parseInt(s2);
				// Pourcent value
				start = end + 1;
				end = labelcontent.indexOf(";", start);
				s3 = labelcontent.substring(start, end);
				end = labelcontent.indexOf(",", start);
				purcent = labelcontent.substring(start, end);

				pourcentvalue = Integer.parseInt(purcent);

				// Table cell will be modified according to the max purcent and max trinucleotide found
				if ((pourcentvalue > CONSTANT.getMaxpurcent())
						&& (number > CONSTANT.getMaxcount()))
				{
					((JLabel) component).setBackground(red);
					((JLabel) component)
							.setBorder(javax.swing.BorderFactory
									.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
				} else
				{
					((JLabel) component).setBackground(white);
				}

				ends = "<html><p>" + s1 + "<br>" + s2 + "<br>" + s3 + "%";
				((JLabel) component).setText(ends);
				((JLabel) component).setHorizontalAlignment(CENTER);

			}
		}
		return component;
	}
}